﻿Public Class SocietyExplorer
    Inherits ExplorerTreeList

    Private EditPanePL As PLBase

    Public Sub New(ByVal aQueryName As String)
        MyBase.New(aQueryName)
    End Sub

    Public Sub New()
        MyBase.New()
    End Sub


    Public Overrides Sub ActionOptionLoad()
        MyBase.ActionOptionLoad()

        DefaultTreeListActionOptionList.ApplySecurity()
        TreeActionOptionListLoad()

        'with the IExplorer interface on oublige que EntityActionOptionListLoad() existe
        MetaControlActionOptionListLoad()
        MetaControlTreeListActionOptionList.ApplySecurity()

    End Sub

    Public Overrides Sub PopulateDetailSection()
        Me.Cursor = Cursors.WaitCursor
        '
        ' Memory management / Help the GC
        If aGridControl IsNot Nothing Then
            aGridControl.Dispose()
            aGridControl = Nothing
        End If

        Dim guidEnfant As Guid
        Dim aPLName As String

        Dim DescriptionLang As String = "_PRM"


        Dim aPaneMetaQueryName As String
        Dim Ametaquerie As MetaQuery
        Dim frmCaption As String = "Society List"        'DeskTopManager.GetMessage("CONNECT") to be implemented when metastring has code

        Try
            guidEnfant = DirectCast(NodeDataRow(Me.KeyFieldName), Guid)
            aPLName = DirectCast(NodeDataRow("PL"), String)

            aPaneMetaQueryName = DirectCast(NodeDataRow("MetaQuerie"), String)
            Ametaquerie = MetaQuery.GetMetaQueryByName(aPaneMetaQueryName)

            'c'est ici qu'on bind les info du noeud qui articule le Edit PANE
            EditPanePL = PLBase.CreateInstanceOf(aPLName, aPaneMetaQueryName)
            '   EditPanePL.SQLWhere = String.Format("Society.....ID_FK IN ({0})", AppManager.GetGCCTSSecurity(IdRepository.ALLOWREAD, IdRepository.SocietyGCCTS("........ID")))

            aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = EditPanePL, .SecureGrid = True, .Name = Ametaquerie.Caption, .FormCtrlCD = MyBase.PanelName}
            If Not Guid.Empty.Equals(guidEnfant) Then

                EditPanePL.SQLWhere = String.Format("{0} = '{1}'", Ametaquerie.GUIDField, guidEnfant)
                If AppManager.ApplicationOption.DescriptionColumnIndex = 3 Then
                    DescriptionLang = "_ALT"
                End If
                If NodeDataRow.Table.Columns.Contains("Society") AndAlso NodeDataRow.Table.Columns.Contains("Description" & DescriptionLang) Then
                    frmCaption = String.Format("{0} - {1}", NodeDataRow("Society"), NodeDataRow("Description" & DescriptionLang))
                Else
                    frmCaption = "Society, Description" & DescriptionLang
                End If


            End If

            ''waiting security design on Societymaster , uncomment when ready
            'If AppManager.SocietyAccessList Is Nothing Then
            '    EditPanePL.AddSQLWhereAnd(String.Format("SocietyID in ({0})", System.Guid.Empty))
            'Else
            '    EditPanePL.AddSQLWhereAnd(String.Format("SocietyID in ({0})", AppManager.SocietyAccessList))
            'End If

            AddHandler aGridControl.DetailCustomRowCellEditForEditing, AddressOf SocietyDetail_CustomRowCellEditForEditing

        Catch ex As Exception
            MessageWindow.ShowMessage(ex)

        End Try


        '
        'On trouve la form pour effacer les controle dedans et ensuite remettre le bon.
        'Comme ca on change le Detail selon la ligne dans L'explorer
        For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
            If aFrm.Name = PanelName Then
                aFrm.Controls.Clear()
                aFrm.Controls.Add(aGridControl)
                aFrm.Text = frmCaption
                aFrm.Show()
                aFrm.Focus()
            End If
            aFrm.Refresh()
        Next

        Me.Cursor = Cursors.Default
    End Sub


    Private Sub Society_GridLayout()
        Try

            Me.Cursor = Cursors.WaitCursor

            PL = New SystemBoxSDK.PL.CoreSDK.Product_PL("Society")
            aGridLayout = New GridLayoutPL() With {.Dock = DockStyle.Fill, .Pl = PL, .FormCtrlCD = Nothing}

            For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
                If aFrm.Name = PanelName Then
                    aFrm.Controls.Clear()
                    aFrm.Controls.Add(aGridLayout)
                    aFrm.Text = aGridLayout.Pl.QueryName
                    aFrm.Show()
                End If
                aFrm.Refresh()
            Next

            AddHandler aGridLayout.InitNewMasterRow, AddressOf InitNewLayoutRow

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            MessageWindow.ShowMessage(ex, MsgBoxStyle.Information)
        End Try
    End Sub





End Class
